|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
InputOutputFileImpl.java | 66.7% | 60% | 71.4% | 63.3% |
|
1 |
/*
|
|
2 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
|
16 |
|
|
17 |
package org.apache.geronimo.ews.ws4j2ee.context.impl;
|
|
18 |
|
|
19 |
import org.apache.geronimo.ews.ws4j2ee.context.InputOutputFile;
|
|
20 |
import org.apache.geronimo.ews.ws4j2ee.toWs.GenerationFault;
|
|
21 |
|
|
22 |
import java.io.File;
|
|
23 |
import java.io.FileInputStream;
|
|
24 |
import java.io.FileNotFoundException;
|
|
25 |
import java.io.FileOutputStream;
|
|
26 |
import java.io.IOException;
|
|
27 |
import java.io.InputStream;
|
|
28 |
import java.io.OutputStream;
|
|
29 |
|
|
30 |
/**
|
|
31 |
* @author hemapani@opensource.lk
|
|
32 |
*/
|
|
33 |
public class InputOutputFileImpl implements InputOutputFile { |
|
34 |
private InputStream instream;
|
|
35 |
private String fileName;
|
|
36 |
private OutputStream outstream;
|
|
37 |
|
|
38 | 11 |
public InputOutputFileImpl(InputStream instream) {
|
39 | 11 |
this.instream = instream;
|
40 |
} |
|
41 |
|
|
42 | 34 |
public InputOutputFileImpl(String fileName) throws GenerationFault { |
43 | 34 |
this.fileName = fileName;
|
44 |
} |
|
45 |
|
|
46 | 0 |
public InputOutputFileImpl(String fileName, InputStream instream) {
|
47 | 0 |
this.instream = instream;
|
48 | 0 |
this.fileName = fileName;
|
49 |
} |
|
50 |
|
|
51 | 74 |
public String fileName() {
|
52 | 74 |
if (fileName == null) |
53 | 11 |
throw new UnsupportedOperationException("asking for file name when input/output is a stream"); |
54 | 63 |
return fileName;
|
55 |
} |
|
56 |
|
|
57 | 0 |
public InputStream getInputStream() throws GenerationFault { |
58 | 0 |
try {
|
59 | 0 |
if (instream == null) { |
60 | 0 |
File file = new File(fileName);
|
61 | 0 |
this.instream = new FileInputStream(file); |
62 |
} |
|
63 | 0 |
return instream;
|
64 |
} catch (FileNotFoundException e) {
|
|
65 | 0 |
e.printStackTrace(); |
66 | 0 |
throw GenerationFault.createGenerationFault(e);
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 | 11 |
public OutputStream getOutStream() throws GenerationFault { |
71 | 11 |
try {
|
72 | 11 |
if (outstream == null) { |
73 | 11 |
File file = new File(fileName);
|
74 | 11 |
File parent = file.getParentFile(); |
75 | 11 |
if (!parent.exists())
|
76 | 0 |
parent.mkdirs(); |
77 | 11 |
this.outstream = new FileOutputStream(file); |
78 |
} |
|
79 | 11 |
return outstream;
|
80 |
} catch (FileNotFoundException e) {
|
|
81 | 0 |
e.printStackTrace(); |
82 | 0 |
throw GenerationFault.createGenerationFault(e);
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
/* (non-Javadoc)
|
|
87 |
* @see java.lang.Object#finalize()
|
|
88 |
*/
|
|
89 | 24 |
protected void finalize() throws Throwable { |
90 | 24 |
try {
|
91 | 24 |
if (outstream != null) |
92 | 7 |
outstream.close(); |
93 | 24 |
if (instream != null) { |
94 | 7 |
instream.close(); |
95 |
} |
|
96 |
} catch (IOException e) {
|
|
97 |
} |
|
98 | 24 |
super.finalize();
|
99 |
} |
|
100 |
|
|
101 |
} |
|
102 |
|
|